#!/bin/sh
#
# 部署笔记前端
#
root_dir="/root/git/"
app_name="mojito-note-web"

# 1 代表首次构建
if [[ $1 == "1" ]]; then
  cd ${root_dir}
  git clone git@gitee.com:itstrongs/${app_name}.git

  cd ${root_dir}${app_name}
  npm install --unsafe-perm=true --allow-root
fi

cd ${root_dir}${app_name}
git pull
npm run build

if docker ps -a | grep -q ${app_name}; then
  docker stop ${app_name}
  docker rm ${app_name}
  docker rmi ${app_name}
fi

docker build -t ${app_name} .
docker run --name ${app_name} -d -p 80:80 -p 433:433 -v /root/nginx/conf/nginx.conf:/etc/nginx/nginx.conf ${app_name}

echo "------------ 部署完成 ------------"
